import java.util.Arrays;
public class Test026 {
    public static void main(String[] args) {
        int[] array={23,6,78,65,98,60,12};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));
        }

    public static void bubbleSort(int[] array) {
        for(int i=0;i<array.length-1;i++){
            boolean flg=false;
            //j<4 可以不减i 减i是对代码进行了优化
            for(int j=0;j<array.length-1-i;j++){
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flg = true;
                }
            }
            if(flg == false){
                break;
            }
        }
    }
}
